package com.igen.rxnetaction;

import android.net.wifi.SupplicantState;
import android.net.wifi.WifiInfo;
import android.os.Bundle;

import com.igen.rxnetaction.sample.R;
import com.igen.rxnetaction.wifi.RxWifi;
import com.igen.rxnetaction.wifi.WifiSignalLevel;
import com.orhanobut.logger.Logger;
import com.trello.rxlifecycle.components.RxActivity;

import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

public class MainActivity extends RxActivity {
    private RxWifi reactiveWifi;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        reactiveWifi = new RxWifi();
        reactiveWifi.observeWifiSignalLevel(getApplicationContext())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<WifiSignalLevel>() {
                    @Override
                    public void call(final WifiSignalLevel level) {
                        final String description = level.description;
                        Logger.d(description);
                    }
                });

        reactiveWifi.observeSupplicantState(getApplicationContext())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<SupplicantState>() {
                    @Override
                    public void call(final SupplicantState ret) {
                        Logger.d(ret);
                    }
                });

        reactiveWifi.observeWifiAccessPointChanges(getApplicationContext())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<WifiInfo>() {
                    @Override
                    public void call(final WifiInfo ret) {
                        Logger.d(ret);
                    }
                });

     /*   reactiveWifi.observeWifiAccessPoints(getApplicationContext())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<List<ScanResult>>() {
                    @Override
                    public void call(final List<ScanResult> ret) {
                        for (ScanResult tmp : ret) {
                            Logger.d(tmp);
                        }
                    }
                });*/
    }
}
